// 1 映入express
const express = require('express')
const {request, response} = require("express");

// 2 创建应用对象
const app = express()

// 3 创建路由规则
app.get('/serve',(request,response)=>{
    response.setHeader('Access-Control-Allow-Origin','*')
    response.send('响应、。。get')
})
app.post('/serve',(request,response)=>{
    response.setHeader('Access-Control-Allow-Origin','*')
    response.setHeader('Access-Control-Allow-Headers','*')
    response.send('响应、。。post')
})
app.options('/serve',(request,response)=>{
    response.setHeader('Access-Control-Allow-Origin','*')
    response.setHeader('Access-Control-Allow-Headers','*')
    response.send('响应、。。options')
})
app.post('/server/json',(request,response)=>{
    response.setHeader('Access-Control-Allow-Origin','*')
    let data = {
        name: 'yuu'
    }
    response.send(data)
})

app.post('/server/ie',(request,response)=>{
    response.setHeader('Access-Control-Allow-Origin','*')
    let data = {
        name: 'yuu'
    }
    response.send(data)
})
app.post('/network',(request,response)=>{
    response.setHeader('Access-Control-Allow-Origin','*')
    setTimeout(()=>{
        response.send('network')
    },3000)
})
app.all('/axios',(request,response)=>{
    response.setHeader('Access-Control-Allow-Origin','*')
    response.setHeader('Access-Control-Allow-Headers','*')

    let result = {
        name: 'yuu'
    }
    response.send(result)
})

app.all('/fetch',(request,response)=>{
    response.setHeader('Access-Control-Allow-Origin','*')
    response.setHeader('Access-Control-Allow-Headers','*')
    response.setHeader('Access-Control-Allow-Methods','*')
    response.send({
        name: 'fetchRequest'
    })
})
// 4 监听端口启动服务
app.listen(8000,()=>{
    console.log('服务启动，端口8000.。。')
})